package com.wep.fence.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wep.fence.domain.R;
import com.wep.fence.dto.RegionDTO;
import com.wep.fence.dto.RegionQuery;
import com.wep.fence.entity.RegionEntity;
import com.wep.fence.service.RegionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController()
@RequestMapping("/region")
@Tag(name = "行政区划管理")
public class RegionController {
    @Resource
    private RegionService regionService;

    /**
     * 行政区划查询
     */
    @Operation(summary = "行政区划列表查询")
    @GetMapping("/list")
    public R<List<RegionEntity>> listByParam(RegionQuery query) {
        List<RegionEntity> resultList = regionService.listByParam(query);
        return R.ok(resultList);
    }

    @Operation(summary = "行政区分页查询")
    @GetMapping("/page")
    public R<IPage<RegionEntity>> pageByParam(RegionQuery query) {
        IPage<RegionEntity> page = regionService.pageByParam(query);
        return R.ok(page);
    }

    @Operation(summary = "根据code查询详情")
    @GetMapping("/getByCode")
    public R<RegionEntity> getByCode(String code) {
        RegionEntity regionEntity = regionService.getByCode(code);
        return R.ok(regionEntity);
    }

    @Operation(summary = "根据code查询该区域下的所有数据")
    @GetMapping("/listChildByCode")
    public R<RegionDTO> listChildByCode(String code, Integer type) {
        RegionDTO resultList = regionService.listChildByCode(code, type);
        return R.ok(resultList);
    }


    @Operation(summary = "根据code查询该的所有上级区域")
    @GetMapping("listParentByCode")
    public R<List<RegionEntity>> listParentByCode(String code) {
        List<RegionEntity> resultList = regionService.listParentByCode(code);
        return R.ok(resultList);
    }

}
